import { useReactive } from "ahooks";
import { useEffect } from "react";
import { useModel } from "umi";

const useRemoteApplication = () => {
    const { remoteData } = useModel("global");
    const { applicationUuid } = useModel("application.info");

    const state = useReactive({
        loading: false,
        remoteApplication: {},
    });

    // 从务链应用运营中心获取应用信息, 通过应用UUID
    const loadRemoteApplication = async () => {
        state.loading = true;
        let res = await remoteData({
            object: "bnt-application-operation-center-service",
            serviceName: "/person/application/getByAiUuid",
            showError: false,
            params: {
                aiUuid: applicationUuid,
                aiType: "桌面端",
            },
        });
        if (res) {
            state.remoteApplication = res;
        }
        state.loading = false;
        return res || {};
    };

    useEffect(() => {
        applicationUuid && loadRemoteApplication();
    }, [applicationUuid]);

    return { ...state, loadRemoteApplication };
};

export default useRemoteApplication;
